﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;

namespace Nody
{
    public abstract class Item
    {
        #region Fields

        ContentManager content;

        protected string inventoryIconPath;
        protected string roomImagePath;

        public bool isLoaded = false;

        #endregion

        #region Properties

        public Texture2D InventoryIcon
        {
            get { return inventoryIcon; }
            protected set { inventoryIcon = value; }
        }
        Texture2D inventoryIcon;

        public Texture2D RoomImage
        {
            get { return roomImage; }
            protected set { roomImage = value; }
        }
        Texture2D roomImage;

        #endregion

        #region Initialization

        public virtual void LoadContent()
        {
            if (content == null)
                content = new ContentManager(Main.Instance.Services, "Content");

            try
            {
                inventoryIcon = content.Load<Texture2D>(inventoryIconPath);
                roomImage = content.Load<Texture2D>(roomImagePath);
            }
            catch (ContentLoadException e)
            {
                if (inventoryIcon == null)
                    inventoryIcon = content.Load<Texture2D>("ui/items/icons/no-icon");
                if (roomImage == null)
                    roomImage = content.Load<Texture2D>("ui/items/icons/no-icon");
            }
            isLoaded = true;
        }

        public virtual void UnloadContent()
        {
            if (content != null)
                content.Unload();
        }

        #endregion
    }
}
